﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AddEdit.aspx.cs" Inherits="CardLogistics.Web.MainPage.CardRecovery.NotSaleCard.AddEdit" %>

<%@ Register Src="../../../Controls/WebUserControl_Nav.ascx" TagName="WebUserControl_Nav"
    TagPrefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>未售问题卡回收-编辑</title>
    <link href="../../../css/style.css" rel="stylesheet" type="text/css" />
    <link href="../../../css/selPage.css" rel="stylesheet" type="text/css" />
    <script src="../../../js/My97DatePicker/WdatePicker.js" type="text/javascript"></script>
    <script src="../../../js/valReq.js" type="text/javascript"></script>
    <script src="../../../js/jquery-1.3.2.min.js" type="text/javascript"></script>
    <script src="../../../js/jquery.tipswindow.2.0.js" type="text/javascript"></script>
    <script type="text/javascript">
        function valReq(issubmit) {
            var altStr = valid_isempty('RECOVERYNO', '回收单号');
            //必须为字母或者数字
            altStr += valid_isnoCh('RECOVERYNO', '回收单号');
            altStr += valid_isempty('RECOVERYDATE', '回收日期');
            altStr += GetCardInfo();
            altStr += valid_isempty('hf_detailId', '详细信息');
            if (altStr != "") {
                alert(altStr);
                return false;
            }
            else {
                if (issubmit == 1) {
                    if (confirm("提交后该信息进入待审批状态不可编辑,确认提交吗?") == true) {
                        return true;
                    }
                    else
                        return false;
                }
                else
                    return true;
            }
        }
        function GetCardInfo() {
            var Data_value = [];
            var errInfo = ""; //返回错误消息
            var vIndex = 0;
            var cSum = 0; //数量
            var StartCardNo = $("input[name=StartCardNo]"); //开始卡号
            var EndCardNo = $("input[name=EndCardNo]"); //  结束卡号
            var CardAmount = $("input[name=CardAmount]"); //数量
            $("input[name='CardAmount']").each(function (i, o) {
                if ($(CardAmount[i]).val() != "0" && $(CardAmount[i]).val() != "") {
                    Data_value[vIndex] = Trim($(StartCardNo[i]).val()) + "|" + Trim($(EndCardNo[i]).val()) + "|" + Trim($(o).val()); //明细值
                    cSum += parseInt(Trim($(CardAmount[i]).val()));
                    vIndex++;
                }
                else if (Trim($(StartCardNo[i]).val()) != "" || Trim($(EndCardNo[i]).val()) != "")
                    errInfo += "第" + (parseInt(vIndex.toString())+1) + "行明细不能为空！\n";
            });
            $("#hf_detailId").val(Data_value.join(";"));
            document.getElementById("tSum").innerHTML = cSum;
            return errInfo;
        }

        $(document).ready(function () {
            //输入数量汇总   $("input[name='EndCardNo'],input[name='StartCardNo']")
            $("#tb_Detail").keyup(function () {
                var cNumber = $("input[name=CardAmount]");
                var csum = 0;
                var cStartCardNo = $("input[name=StartCardNo]"); //开始卡号
                var cEndCardNo = $("input[name=EndCardNo]"); //  结束卡号
                $("input[name='EndCardNo']").each(function (i, o) {
                    if ($(cEndCardNo[i]).val().length == 8 && $(cStartCardNo[i]).val().length == 8) {
                        var cardam = parseInt(Trim($(cEndCardNo[i]).val())) - parseInt(Trim($(cStartCardNo[i]).val())) + 1;
                        $(cNumber[i]).val(cardam);
                        csum += cardam;
                    }
                    else {
                        $(cNumber[i]).val(0);
                    }
                });
                document.getElementById("tSum").innerHTML = csum;
            });
        });

        function BindDetailInfo() {
            var cSum = 0; //数量
            var cStartCardNo = $("input[name=StartCardNo]"); //开始卡号
            var cEndCardNo = $("input[name=EndCardNo]"); //  结束卡号
            var cCardAmount = $("input[name=CardAmount]"); //数量

            var ids = document.getElementById("hf_detailId").value;
            var str1 = ids.split(";");
            for (var i = 0; i < str1.length; i++) {
                if (str1[i] != "") {
                    $(cStartCardNo[i]).val(str1[i].split("|")[0]);
                    $(cEndCardNo[i]).val(str1[i].split("|")[1]);
                    $(cCardAmount[i]).val(str1[i].split("|")[2]);

                    cSum += parseInt(str1[i].split("|")[2]);
                }
            }
            document.getElementById("tSum").innerHTML = cSum;
        }
        window.onload = function () { BindDetailInfo(); }

        //验证是否选择了待上传文件
        function LoadFile() {
            var fstr = document.getElementById("FileUpload1").value;
            fstr.outerHTML = fstr.outerHTML;
            if (fstr == "") {
                alert("请选择您要上传的文件！");
                return false;
            }
            return true;
        }
    </script>
</head>
<body>
    <form id="frmFather" runat="server">
    <uc1:WebUserControl_Nav ID="WebUserControl_Nav1" runat="server" />
    <%=TitleName %>
    <input type="hidden" id="hf_detailId" name="hf_detailId" runat="server" />
    <table class="theForm" width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
            <td class="titleTxt">
                回收单号：
            </td>
            <td class="contentTxt">
                <input id="RECOVERYNO" runat="server" type="text" class="dfinputNoEmp" maxlength="15" />
            </td>
            <td class="titleTxt">
                回收日期：
            </td>
            <td class="contentTxt">
                <input id="RECOVERYDATE" runat="server" type="text" class="Wdate" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" />
            </td>
        </tr>
        <tr runat="server" id="tr_SALE">
            <td class="titleTxt">
                返还网点：
            </td>
            <td class="contentTxt">
                <asp:DropDownList ID="RETURNPOINT" runat="server" class="dfinputNoEmp">
                </asp:DropDownList>
            </td>
            <td class="titleTxt">
            </td>
            <td class="contentTxt">
            </td>
        </tr>
        <tr>
            <td class="titleTxt">
                备注：
            </td>
            <td colspan="3">
                <input id="REMARKS" runat="server" type="text" class="dfinput" style="width: 90%;"
                    maxlength="200" />
            </td>
        </tr>
        <tr>
            <td colspan="4" style="text-align: left; border: 1px;">
                <asp:FileUpload ID="FileUpload1" runat="server" CssClass="dfFile" Width="350px" />
                <asp:Button ID="btnImport" runat="server" Text="导入" CssClass="scbtn" OnClientClick="return LoadFile();"
                    OnClick="btnImport_Click" />
                <asp:Button ID="btnDownLoad" runat="server" Text="模板下载" CssClass="scbtn" OnClick="btnDownLoad_Click" />
            </td>
        </tr>
        <tr>
            <td colspan="4">
                <div class="ddetail" style="height: 270px;">
                    <table class="tabledetail" id="tb_Detail">
                        <thead>
                            <tr>
                                <th width="65px">
                                    序号
                                </th>
                                <th width="200px">
                                    开始卡号
                                </th>
                                <th width="200px">
                                    结束卡号
                                </th>
                                <th width="200px">
                                    数量
                                </th>
                                <th>
                                    &nbsp;
                                </th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td width="65px" align="center">
                                    1
                                </td>
                                <td width="200px">
                                    <input name="StartCardNo" type="text" onkeydown="onlyNum();" maxlength="8" />
                                </td>
                                <td width="200px">
                                    <input name="EndCardNo" type="text" onkeydown="onlyNum();" maxlength="8" />
                                </td>
                                <td width="200px">
                                    <input name="CardAmount" type="text" value="0" onkeydown="onlyNum();" maxlength="9" />
                                </td>
                                <td>
                                    &nbsp;
                                </td>
                            </tr>
                            <tr>
                                <td width="65px" align="center">
                                    2
                                </td>
                                <td width="200px">
                                    <input name="StartCardNo" type="text" onkeydown="onlyNum();" maxlength="8" />
                                </td>
                                <td width="200px">
                                    <input name="EndCardNo" type="text" onkeydown="onlyNum();" maxlength="8" />
                                </td>
                                <td width="200px">
                                    <input name="CardAmount" type="text" value="0" onkeydown="onlyNum();" maxlength="9" />
                                </td>
                                <td>
                                    &nbsp;
                                </td>
                            </tr>
                            <tr>
                                <td width="65px" align="center">
                                    3
                                </td>
                                <td width="200px">
                                    <input name="StartCardNo" type="text" onkeydown="onlyNum();" maxlength="8" />
                                </td>
                                <td width="200px">
                                    <input name="EndCardNo" type="text" onkeydown="onlyNum();" maxlength="8" />
                                </td>
                                <td width="200px">
                                    <input name="CardAmount" type="text" value="0" onkeydown="onlyNum();" maxlength="9" />
                                </td>
                                <td>
                                    &nbsp;
                                </td>
                            </tr>
                            <tr>
                                <td width="65px" align="center">
                                    4
                                </td>
                                <td width="200px">
                                    <input name="StartCardNo" type="text" onkeydown="onlyNum();" maxlength="8" />
                                </td>
                                <td width="200px">
                                    <input name="EndCardNo" type="text" onkeydown="onlyNum();" maxlength="8" />
                                </td>
                                <td width="200px">
                                    <input name="CardAmount" type="text" value="0" onkeydown="onlyNum();" maxlength="9" />
                                </td>
                                <td>
                                    &nbsp;
                                </td>
                            </tr>
                            <tr>
                                <td width="65px" align="center">
                                    5
                                </td>
                                <td width="200px">
                                    <input name="StartCardNo" type="text" onkeydown="onlyNum();" maxlength="8" />
                                </td>
                                <td width="200px">
                                    <input name="EndCardNo" type="text" onkeydown="onlyNum();" maxlength="8" />
                                </td>
                                <td width="200px">
                                    <input name="CardAmount" type="text" value="0" onkeydown="onlyNum();" maxlength="9" />
                                </td>
                                <td>
                                    &nbsp;
                                </td>
                            </tr>
                            <tr>
                                <td width="65px" align="center">
                                    6
                                </td>
                                <td width="200px">
                                    <input name="StartCardNo" type="text" onkeydown="onlyNum();" maxlength="8" />
                                </td>
                                <td width="200px">
                                    <input name="EndCardNo" type="text" onkeydown="onlyNum();" maxlength="8" />
                                </td>
                                <td width="200px">
                                    <input name="CardAmount" type="text" value="0" onkeydown="onlyNum();" maxlength="9" />
                                </td>
                                <td>
                                    &nbsp;
                                </td>
                            </tr>
                            <tr>
                                <td width="65px" align="center">
                                    7
                                </td>
                                <td width="200px">
                                    <input name="StartCardNo" type="text" onkeydown="onlyNum();" maxlength="8" />
                                </td>
                                <td width="200px">
                                    <input name="EndCardNo" type="text" onkeydown="onlyNum();" maxlength="8" />
                                </td>
                                <td width="200px">
                                    <input name="CardAmount" type="text" value="0" onkeydown="onlyNum();" maxlength="9" />
                                </td>
                                <td>
                                    &nbsp;
                                </td>
                            </tr>
                            <tr>
                                <td width="65px" align="center">
                                    8
                                </td>
                                <td width="200px">
                                    <input name="StartCardNo" type="text" onkeydown="onlyNum();" maxlength="8" />
                                </td>
                                <td width="200px">
                                    <input name="EndCardNo" type="text" onkeydown="onlyNum();" maxlength="8" />
                                </td>
                                <td width="200px">
                                    <input name="CardAmount" type="text" value="0" onkeydown="onlyNum();" maxlength="9" />
                                </td>
                                <td>
                                    &nbsp;
                                </td>
                            </tr>
                            <tr>
                                <td width="65px" align="center">
                                    9
                                </td>
                                <td width="200px">
                                    <input name="StartCardNo" type="text" onkeydown="onlyNum();" maxlength="8" />
                                </td>
                                <td width="200px">
                                    <input name="EndCardNo" type="text" onkeydown="onlyNum();" maxlength="8" />
                                </td>
                                <td width="200px">
                                    <input name="CardAmount" type="text" value="0" onkeydown="onlyNum();" maxlength="9" />
                                </td>
                                <td>
                                    &nbsp;
                                </td>
                            </tr>
                            <tr>
                                <td width="65px" align="center">
                                    10
                                </td>
                                <td width="200px">
                                    <input name="StartCardNo" type="text" onkeydown="onlyNum();" maxlength="8" />
                                </td>
                                <td width="200px">
                                    <input name="EndCardNo" type="text" onkeydown="onlyNum();" maxlength="8" />
                                </td>
                                <td width="200px">
                                    <input name="CardAmount" type="text" value="0" onkeydown="onlyNum();" maxlength="9" />
                                </td>
                                <td>
                                    &nbsp;
                                </td>
                            </tr>
                            <%=AddTr.ToString() %>
                        </tbody>
                    </table>
                </div>
                <table class="tablesum">
                    <tr>
                        <td width="65px">
                            &nbsp;
                        </td>
                        <td width="200px" style="text-align: center;">
                            合计
                        </td>
                        <td width="200px">
                            &nbsp;
                        </td>
                        <td id="tSum" style="text-align: right" width="200px">
                            0
                        </td>
                        <td>
                            &nbsp;
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr class="btntr">
            <td colspan="4" align="center">
                <asp:Button ID="btn_Submit" CssClass="btn" runat="server" Text="保存并提交" OnClientClick="return valReq(1);"
                    OnClick="btn_Submit_Click" />
                <asp:Button ID="btn_Add" CssClass="btn" runat="server" Text="保存" OnClientClick="return valReq(0);"
                    OnClick="btn_Add_Click" />
                <input type="button" class="btn" value="返回" onclick="javascript:history.go(-1);" />
            </td>
        </tr>
    </table>
    </form>
</body>
</html>
